Managed type thread safety#2322
Merged
andrei-marinica merged 10 commits intofeat/mdropfrom Mar 30, 2026
Merged
Conversation
|
Contract comparison - from 35e26ae to 5ac255d
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a dedicated handle wrapper for StaticApi to improve managed-type thread-safety semantics (thread-local handle space), plus new tooling binaries to validate threading behavior and benchmark managed-type memory retention in the scenario environment.
Changes:
- Introduce
StaticApiHandleand switchStaticApiBackend::HandleTypefromRawHandleto the new wrapper type. - Adjust managed-type raw-handle extraction to use
HandleConstraints::get_raw_handle()(supporting non-i32handle wrapper types). - Add
managed-mem-benchbinaries for leak/memory lifecycle benchmarking and multi-threaded behavior checks.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/managed-mem-bench/src/bench_threading.rs | New multi-thread validation binary for StaticApi handle isolation/reset/round-trip patterns. |
| tools/managed-mem-bench/src/bench_leak.rs | New allocation-tracking benchmark binary for managed-type lifecycle memory behavior. |
| tools/managed-mem-bench/Cargo.toml | Registers the two new binaries. |
| framework/scenario/src/api/impl_vh/static_api_handle.rs | Adds StaticApiHandle wrapper implementing HandleConstraints. |
| framework/scenario/src/api/impl_vh/static_api.rs | Switches StaticApiBackend to use StaticApiHandle. |
| framework/scenario/src/api/impl_vh/debug_handle.rs | Attempts to further restrict DebugHandle cross-thread usage via phantom marker. |
| framework/scenario/src/api/impl_vh.rs | Wires in new modules/exports (static_api_handle, renamed debug handle module). |
| framework/scenario/src/api.rs | Re-exports StaticApiHandle from scenario API. |
| framework/base/src/types/managed/managed_type_trait.rs | Updates ManagedType::get_raw_handle() to use HandleConstraints API (wrapper-friendly). |
| framework/scenario/tests/derive_managed_vec_item_biguint_test.rs | Imports HandleConstraints to use to_be_bytes() on handle type. |
| framework/scenario/tests/derive_managed_vec_item_esdt_token_payment_test.rs | Same as above for ESDT payment-related test. |
Comments suppressed due to low confidence (1)
framework/scenario/src/api/impl_vh/debug_handle.rs:24
- The
_phantom: PhantomData<*const ()>field does not actually preventDebugHandlefrom beingSend/Sync(raw pointers areSend+Sync), so the comment is currently inaccurate and the extra safety barrier isn’t effective. If you wantDebugHandleto be!Send/!Sync, use a phantom marker over a type that is!Send/!Sync(e.g.PhantomData<std::rc::Rc<()>>) or an explicit negative impl where applicable.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request overview
Adds a dedicated handle wrapper for
StaticApito improve managed-type thread-safety semantics (thread-local handle space), plus new tooling binaries to validate threading behavior and benchmark managed-type memory retention in the scenario environment.Changes:
StaticApiHandleand switchStaticApiBackend::HandleTypefromRawHandleto the new wrapper type.HandleConstraints::get_raw_handle()(supporting non-i32handle wrapper types).managed-mem-benchbinaries for leak/memory lifecycle benchmarking and multi-threaded behavior checks.